package com.moon.game.manager;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.moon.game.resource.model.Mission;

/**
 * @description 任务加载
 * @author Ranger 作者 E-mail:haozi000005@163.com
 * @version 创建时间：2012-8-2 下午3:18:48
 */
public class MissionMG {
	private MissionMG() {}
	public static MissionMG instance = new MissionMG();
	public void init() {
		if (instance == null) {
			instance = new MissionMG();
		}
		loadMissions();
	}
	/**任务资源*/
	public static Map<Integer, Mission> missionRes = new HashMap<Integer, Mission>();
	/**不同等级下的任务列表*/
	public static Map<Integer, List<Mission>> levelMissionMap = new HashMap<Integer, List<Mission>>();
	public void loadMissions() {
		List<Mission> missions = DBManager.queryAllMissions();
		for (Mission mission : missions) {
			missionRes.put(mission.getId(), mission);
			List<Mission> levelMissions = levelMissionMap.get(mission.getLevel());
			if (levelMissions == null) {
				levelMissions = new ArrayList<Mission>();
			}
			levelMissions.add(mission);
			levelMissionMap.put(mission.getLevel(), levelMissions);
		}
	}
	
	/**获取等级对应的任务列表*/
	public List<Mission> getLevelMissionList(int level) {
		return levelMissionMap.get(level);
	}
	/**根据任务id获取任务*/
	public Mission getMission(int missionId) {
		return missionRes.get(missionId);
	}
	/**获取任务资源*/
	public Map<Integer, Mission> getMissionRes() {
		return missionRes;
	}
}
